<template>
  <div>
    <el-table v-loading="loading" :data="items" stripe  border>
      <el-table-column label="工单编号" min-width="150">
        <template slot-scope="scope" >
          <div @click="toWorkOrder" style="color: #005EDF">
            {{ scope.row?scope.row.wo_number:''}}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="工单类型" min-width="100">
        <template slot-scope="scope">
          {{ scope.row.type }}
        </template>
      </el-table-column>
      <el-table-column prop="status" min-width="100" label="工单状态" />

      <el-table-column label="负责人" min-width="130">
        <template slot-scope="scope">
          {{ scope.row.users?scope.row.users.filter(item=> item.is_master===1)[0].user.realname:'' }}
        </template>
      </el-table-column>
      <el-table-column label="完成时间" min-width="200">
        <template slot-scope="scope">
          {{scope.row.histories? scope.row.histories.filter(item=>item.status==='已完成').length?scope.row.histories.filter(item=>item.status==='已完成')[0].create_time_format:'':'' }}
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {mapGetters} from "vuex";
export default {
  name: "Product",
  components:{
  },
  props:['id'],
  computed: {
    ...mapGetters(["permission"])
  },

  data() {
    return {
      workOrderId:'',
      loading: false,
      items: []
    };
  },
  watch:{
    id(){
      if(this.id){
        this.loadData()
      }
    }
  },
  mounted() {
    if(this.id){
      this.loadData();
    }
  },
  methods: {
    toWorkOrder(){
      this.$router.push('/workTickets/workTickets/info?id=' + this.workOrderId)
    },
    loadData() {
      this.loading = true;
      this.$http.get(`/events/${this.id}/work_order`).then((res) => {
        if(res.data.data!==null){
          this.items = [res.data.data];
          this.workOrderId = res.data.data.id
          this.$forceUpdate()

        }

        this.loading = false;
      });
    },
  }
};
</script>
